from rest_framework import serializers

from user.models import User


class UserCreateSerializer(serializers.ModelSerializer):

    class Meta:
        model = User
        fields = '__all__'

    def create(self, validated_data):
        user = User.objects.create(**validated_data)

        # 密码加密
        user.set_password(validated_data['password'])
        user.save()

        return user
